Skip to contentSkip to conversation

Change in openvpn[master]: dco_linux: parse stats in PEER_DEL notification if available

Openvpn-devel ralf_lici (Code Review) 1 participant 3 messages Dec 11, 2025 – Feb 10 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1765448957000.I7f3b95cacdf359536e827f176f2b81da4b00f22f@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email

to review the following change.

Change subject: dco_linux: parse stats in PEER_DEL notification if available
......................................................................

dco_linux: parse stats in PEER_DEL notification if available

Upon receiving a PEER_DEL notification, update the peer's statistics counters if such information is present in the message. This allows openvpn to avoid issuing a PEER_GET request-reply, eliminating issues caused by overlapping traffic on the netlink socket when multiple PEER_DEL notifications are received simultaneously.

Since we cannot assume the kernel module will always send a PEER_DEL with statistics, introduce a boolean flag to track whether the counters were already updated or if a PEER_GET request is still required.

Change-Id I7f3b95cacdf359536e827f176f2b81da4b00f22f

---
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_freebsd.h
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/multi.c

9 files changed, 82 insertions(+), 45 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/1434/1

src/openvpn/dco.c +6 -0
index 7abdad3..3329ff9 100644
@@ -778,4 +778,10 @@
 #endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32) */
 }
 
+bool
+dco_del_peer_stats_updated(dco_context_t *dco)
+{
+    return dco->dco_del_peer_stats_updated;
+}
+
 #endif /* defined(ENABLE_DCO) */
src/openvpn/dco.h +16 -0
index cd6e32a..a81a968 100644
@@ -242,6 +242,16 @@
 int dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err);
 
 /**
+ * Check if the peer stats were already updated while parsing a PEER_DEL
+ * notification. This is simply a getter for the internal
+ * dco->dco_del_peer_stats_updated field.
+ *
+ * @param dco       DCO device context
+ * @return          value of dco->dco_del_peer_stats_updated
+ */
+bool dco_del_peer_stats_updated(dco_context_t *dco);
+
+/**
  * Retrieve the list of ciphers supported by the current platform
  *
  * @return                   list of colon-separated ciphers
@@ -377,6 +387,12 @@
     return 0;
 }
 
+static inline bool
+dco_del_peer_stats_updated(dco_context_t *dco)
+{
+    return false;
+}
+
 static inline const char *
 dco_get_supported_ciphers(void)
 {
src/openvpn/dco_freebsd.c +6 -3
index d1ad092..e47ddd2 100644
@@ -559,13 +559,13 @@
     return ret;
 }
 
-static void
+static bool
 dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlist_t *nvl)
 {
     if (peerid >= m->max_clients || !m->instances[peerid])
     {
         msg(M_WARN, "dco_update_peer_stat: invalid peer ID %u returned by kernel", peerid);
-        return;
+        return false;
     }
 
     struct multi_instance *mi = m->instances[peerid];
@@ -575,6 +575,7 @@
 
     msg(D_DCO_DEBUG, "%s: peer-id %u, dco_read_bytes: " counter_format " dco_write_bytes: " counter_format,
         __func__, peerid, mi->context.c2.dco_read_bytes, mi->context.c2.dco_write_bytes);
+    return true;
 }
 
 int
@@ -620,6 +621,7 @@
     {
         case OVPN_NOTIF_DEL_PEER:
             dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
+            dco->dco_del_peer_stats_updated = false;
 
             if (nvlist_exists_number(nvl, "del_reason"))
             {
@@ -642,12 +644,13 @@
 
                 if (dco->c->mode == CM_TOP)
                 {
-                    dco_update_peer_stat(dco->c->multi, dco->dco_message_peer_id, bytes);
+                    dco->dco_del_peer_stats_updated = dco_update_peer_stat(dco->c->multi, dco->dco_message_peer_id, bytes);
                 }
                 else
                 {
                     dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
                     dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+                    dco->dco_del_peer_stats_updated = true;
                 }
             }
 
src/openvpn/dco_freebsd.h +1 -0
index 5e2a552..72056b0 100644
@@ -60,6 +60,7 @@
     int dco_message_type;
     int dco_message_peer_id;
     int dco_del_peer_reason;
+    bool dco_del_peer_stats_updated;
     struct sockaddr_storage dco_float_peer_ss;
 
     struct context *c;
src/openvpn/dco_linux.c +49 -41

143 lines not on this page · raw message

src/openvpn/dco_linux.h +1 -0
index efd5b27..e275061 100644
@@ -80,6 +80,7 @@
     int dco_message_peer_id;
     int dco_message_key_id;
     int dco_del_peer_reason;
+    bool dco_del_peer_stats_updated;
     struct sockaddr_storage dco_float_peer_ss;
 } dco_context_t;
 
src/openvpn/dco_win.c +1 -0
index 94f043f..030d353 100644
@@ -681,6 +681,7 @@
         dco->dco_message_peer_id = dco->notif_buf.PeerId;
         dco->dco_message_type = dco->notif_buf.Cmd;
         dco->dco_del_peer_reason = dco->notif_buf.DelPeerReason;
+        dco->dco_del_peer_stats_updated = false;
         dco->dco_float_peer_ss = dco->notif_buf.FloatAddress;
     }
     else
src/openvpn/dco_win.h +1 -0
index 02b8389..599f41d 100644
@@ -53,6 +53,7 @@
     int dco_message_peer_id;
     int dco_message_type;
     int dco_del_peer_reason;
+    bool dco_del_peer_stats_updated;
     struct sockaddr_storage dco_float_peer_ss;
 
     struct context *c;
src/openvpn/multi.c +1 -1
index 153695c..4c7d3e2 100644
@@ -510,7 +510,7 @@
 static void
 setenv_stats(struct multi_context *m, struct context *c)
 {
-    if (dco_enabled(&m->top.options))
+    if (dco_enabled(&m->top.options) && !dco_del_peer_stats_updated(&m->top.c1.tuntap->dco))
     {
         if (dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, false) < 0)
         {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7f3b95cacdf359536e827f176f2b81da4b00f22f
Gerrit-Change-Number: 1434
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

ralf_lici has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email )

Change subject: dco_linux: parse stats in PEER_DEL notification if available
......................................................................

Patch Set 1:

(1 comment)

Patchset:

PS1:
An ovpn backport of this feature can be compiled from https://github.com/ralflici/ovpn-backports. Check out the branch stats-in-peer-del, and then follow the usual recipe (backports-ctl.sh get-ovpn && make && make install).

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7f3b95cacdf359536e827f176f2b81da4b00f22f
Gerrit-Change-Number: 1434
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Thu, 11 Dec 2025 10:33:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

ralf_lici has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email )

Change subject: dco_linux: parse stats in PEER_DEL notification if available
......................................................................

Patch Set 1:

(1 comment)

Patchset:

PS1:
As discussed on IRC, we will wait for the kernel patch to land before merging this, to avoid any potential breakage.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1434?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7f3b95cacdf359536e827f176f2b81da4b00f22f
Gerrit-Change-Number: 1434
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Feb 2026 13:45:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No